<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/vue/2.6.11/vue.min.js"></script>
</head>
<body>
    <div id="app">
        {{msg|foo}} <br>
        {{msg|bar(3)}} <br>
    </div>    

    <div id="app2">
        {{msg|foo|bar(10)}}
    </div>

    <script>

        // 定义Vue的全局过滤器，过滤器的名字叫做foo
        Vue.filter("foo", function(data) {
            var n = parseInt(Math.random() * 100 + 1);
            return data + " " + n;
        });

        Vue.filter("bar", function(data, n) {
           var str = "";
           for(var i = 1; i <= n; i++) {
            str += " " + data + " ";
           } 
           return str;
        })

        // 第一个Vue实例
        var app = new Vue({
            el: "#app",
            data: {
                msg:"无崖子"
            }
        });

        // 第二个Vue实例
        var app2 = new Vue({
            el: "#app2",
            data: {
                msg: "丁春秋"
            }
        });
    </script>
</body>
</html>